package com.lagou.Server;

import com.lagou.Client.ClientView;
import com.lagou.model.UserMessage;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

public class ServerView {
    private ServerDao sd;
    private ServerInitClose sic;
    public ServerView(ServerInitClose sic,ServerDao sd){
        this.sic=sic;
        this.sd=sd;
    }
    public void serverReceive() throws IOException, ClassNotFoundException {
        UserMessage tum = (UserMessage) sic.getOis().readObject();
        System.out.println("接收到的消息是:" + tum);
        if (sd.serverManagerCheck(tum.getUser())) {
            tum.setType("success");
        } else {
            tum.setType("fail");
        }
        sic.getOos().writeObject(tum);
        System.out.println("服务器发送校验结果成功!");
        //接收客户端发来的添加学员的信息
        Object o=null;
        boolean flag=true;
        while (flag) {
            o = sic.getOis().readObject();
            if ("false".equals(o)) {
                System.out.println("添加学员完成!");
                System.out.println("__________________________________________________");
                flag=false;
            } else {
                System.out.println("服务器接收到的添加学员的信息是:" + o);
            }
        }
        Object o1 = sic.getOis().readObject();
        System.out.println("服务器接收到的删除的学员信息是:"+o1);
        Object o2=sic.getOis().readObject();
        System.out.println("服务器接收到的删除该学员后的全部学员信息是:"+o2);
        String str1="success";
        sic.getOos().writeObject(str1);

        System.out.println("__________________________________________________");
        Object o3 = sic.getOis().readObject();
        System.out.println("服务器接收到的修改的该学员信息是:"+o3);
        String str2="success";
        sic.getOos().writeObject(str2);
        System.out.println("__________________________________________________");
        Object o4 = sic.getOis().readObject();
        System.out.println("服务器接收到的查询的该学员信息是:"+o4);
        String str3="success";
        sic.getOos().writeObject(str3);
    }
}
